<?php
/**
 * Ecma-262 5rd 7.6.1
 *
 */
class ReservedWord extends IdentifierName {
    
    const KeyWord = 0;
    const FutureReservedWord = 1;
    const NullLiteral = 2;
    const BooleanLiteral = 3;
    
    public static $KeyWordList = array(
        'break',        'do',        'instanceof',    'typeof',
        'case',         'else',      'new',           'var',
        'catch',        'finally',   'return',        'void',
        'continue',     'for',       'switch',        'while',
        'debugger',     'function',  'this',          'with',
        'default',      'if',        'throw',         'delete',
        'in',           'try'
    );
    
    public static $FutureReservedWordList = array(
        'class',        'enum',      'extends',       'super',
        'const',        'export',    'import'
    );
    
    // in strict mode
    public static $FutureReservedWordListInStrictMode = array(
        'implements',   'let',       'private',       'public',
        'interface',    'package',   'protected',     'static',
        'yield'
    );
    
    public static $NullLiteralList = array(
        'null'
    );
    
    public static $BooleanLiteralList = array(
        'true',         'false'
    );
    
    public function __construct(){
        parent::__construct ();
        $this->idType = IdentifierName::IsReservedWord;
    }
    
    public static function isReservedWord($id,$isInStrictMode=false){
        if(in_array($id, self::$KeyWordList)){
            return true;
        }
        
        if(in_array($id, self::$FutureReservedWordList)){
            return true;
        }
        
        if(in_array($id, self::$BooleanLiteralList)){
            return true;
        }
        
        if(in_array($id, self::$NullLiteralList)){
            return true;
        }
        
        if($isInStrictMode && in_array($id, self::$FutureReservedWordListInStrictMode)){
            return true;
        }
        
        return false;
    }
}